from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-21 14:05:59.528223
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 21, Mar, 2021
Time: 14:06:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.0264
Nobs: 237.000 HQIC: -47.8126
Log likelihood: 2792.10 FPE: 1.01140e-21
AIC: -48.3434 Det(Omega_mle): 6.97246e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465322 0.131430 3.540 0.000
L1.Burgenland 0.064883 0.066274 0.979 0.328
L1.Kärnten -0.205895 0.056215 -3.663 0.000
L1.Niederösterreich 0.138596 0.148458 0.934 0.351
L1.Oberösterreich 0.264455 0.133824 1.976 0.048
L1.Salzburg 0.210107 0.071885 2.923 0.003
L1.Steiermark 0.106769 0.095728 1.115 0.265
L1.Tirol 0.104028 0.064162 1.621 0.105
L1.Vorarlberg -0.001386 0.059264 -0.023 0.981
L1.Wien -0.132973 0.122794 -1.083 0.279
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.471655 0.155658 3.030 0.002
L1.Burgenland 0.018093 0.078491 0.231 0.818
L1.Kärnten 0.349086 0.066578 5.243 0.000
L1.Niederösterreich 0.089886 0.175825 0.511 0.609
L1.Oberösterreich -0.100608 0.158493 -0.635 0.526
L1.Salzburg 0.187654 0.085137 2.204 0.028
L1.Steiermark 0.191905 0.113375 1.693 0.091
L1.Tirol 0.131670 0.075990 1.733 0.083
L1.Vorarlberg 0.157705 0.070188 2.247 0.025
L1.Wien -0.484355 0.145430 -3.330 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.310088 0.061375 5.052 0.000
L1.Burgenland 0.089658 0.030949 2.897 0.004
L1.Kärnten -0.018948 0.026251 -0.722 0.470
L1.Niederösterreich 0.061078 0.069327 0.881 0.378
L1.Oberösterreich 0.305152 0.062493 4.883 0.000
L1.Salzburg 0.013114 0.033569 0.391 0.696
L1.Steiermark -0.007917 0.044703 -0.177 0.859
L1.Tirol 0.068095 0.029962 2.273 0.023
L1.Vorarlberg 0.101342 0.027675 3.662 0.000
L1.Wien 0.084778 0.057342 1.478 0.139
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219012 0.065308 3.354 0.001
L1.Burgenland 0.000593 0.032932 0.018 0.986
L1.Kärnten 0.014200 0.027934 0.508 0.611
L1.Niederösterreich 0.034443 0.073770 0.467 0.641
L1.Oberösterreich 0.395366 0.066498 5.946 0.000
L1.Salzburg 0.082198 0.035720 2.301 0.021
L1.Steiermark 0.173666 0.047568 3.651 0.000
L1.Tirol 0.043703 0.031882 1.371 0.170
L1.Vorarlberg 0.080324 0.029448 2.728 0.006
L1.Wien -0.043270 0.061017 -0.709 0.478
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.516896 0.128912 4.010 0.000
L1.Burgenland 0.061384 0.065004 0.944 0.345
L1.Kärnten 0.005197 0.055138 0.094 0.925
L1.Niederösterreich -0.034457 0.145614 -0.237 0.813
L1.Oberösterreich 0.153808 0.131260 1.172 0.241
L1.Salzburg 0.069546 0.070508 0.986 0.324
L1.Steiermark 0.097032 0.093894 1.033 0.301
L1.Tirol 0.218636 0.062933 3.474 0.001
L1.Vorarlberg 0.027906 0.058128 0.480 0.631
L1.Wien -0.105316 0.120442 -0.874 0.382
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187517 0.095287 1.968 0.049
L1.Burgenland -0.023277 0.048049 -0.484 0.628
L1.Kärnten -0.012830 0.040756 -0.315 0.753
L1.Niederösterreich 0.001795 0.107633 0.017 0.987
L1.Oberösterreich 0.418356 0.097022 4.312 0.000
L1.Salzburg 0.007409 0.052117 0.142 0.887
L1.Steiermark -0.016171 0.069403 -0.233 0.816
L1.Tirol 0.167006 0.046518 3.590 0.000
L1.Vorarlberg 0.050250 0.042966 1.170 0.242
L1.Wien 0.225900 0.089026 2.537 0.011
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.251200 0.123489 2.034 0.042
L1.Burgenland 0.020019 0.062270 0.321 0.748
L1.Kärnten -0.050053 0.052819 -0.948 0.343
L1.Niederösterreich -0.054645 0.139488 -0.392 0.695
L1.Oberösterreich -0.024775 0.125738 -0.197 0.844
L1.Salzburg 0.077152 0.067542 1.142 0.253
L1.Steiermark 0.366240 0.089944 4.072 0.000
L1.Tirol 0.449628 0.060285 7.458 0.000
L1.Vorarlberg 0.156348 0.055683 2.808 0.005
L1.Wien -0.186032 0.115375 -1.612 0.107
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127943 0.144369 0.886 0.375
L1.Burgenland 0.028327 0.072799 0.389 0.697
L1.Kärnten -0.059282 0.061750 -0.960 0.337
L1.Niederösterreich 0.204352 0.163074 1.253 0.210
L1.Oberösterreich -0.021237 0.146998 -0.144 0.885
L1.Salzburg 0.246403 0.078962 3.121 0.002
L1.Steiermark 0.138321 0.105152 1.315 0.188
L1.Tirol 0.039388 0.070479 0.559 0.576
L1.Vorarlberg 0.073723 0.065098 1.132 0.257
L1.Wien 0.222960 0.134883 1.653 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579304 0.078509 7.379 0.000
L1.Burgenland -0.034130 0.039588 -0.862 0.389
L1.Kärnten -0.019756 0.033580 -0.588 0.556
L1.Niederösterreich 0.015755 0.088681 0.178 0.859
L1.Oberösterreich 0.315495 0.079939 3.947 0.000
L1.Salzburg 0.013390 0.042940 0.312 0.755
L1.Steiermark -0.017203 0.057183 -0.301 0.764
L1.Tirol 0.084749 0.038327 2.211 0.027
L1.Vorarlberg 0.113295 0.035401 3.200 0.001
L1.Wien -0.042316 0.073350 -0.577 0.564
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134489 0.050823 0.182922 0.238616 0.065474 0.136158 -0.026861 0.160673
Kärnten 0.134489 1.000000 0.005671 0.194840 0.168106 -0.103091 0.144365 0.018034 0.304236
Niederösterreich 0.050823 0.005671 1.000000 0.261011 0.063458 0.267925 0.163024 0.052484 0.312038
Oberösterreich 0.182922 0.194840 0.261011 1.000000 0.288596 0.262333 0.085299 0.069102 0.138653
Salzburg 0.238616 0.168106 0.063458 0.288596 1.000000 0.119280 0.069258 0.088096 -0.003112
Steiermark 0.065474 -0.103091 0.267925 0.262333 0.119280 1.000000 0.120891 0.118856 -0.123569
Tirol 0.136158 0.144365 0.163024 0.085299 0.069258 0.120891 1.000000 0.167631 0.150614
Vorarlberg -0.026861 0.018034 0.052484 0.069102 0.088096 0.118856 0.167631 1.000000 0.019971
Wien 0.160673 0.304236 0.312038 0.138653 -0.003112 -0.123569 0.150614 0.019971 1.000000